package com.qch.concurrent.demo_03_callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author qch
 * @Date 2021/7/26

 */
public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        MyCallable myCallable = new MyCallable();
        FutureTask<String> stringFutureTask = new FutureTask<String>(myCallable);
        //启动线程，执行callable的业务
        new Thread(stringFutureTask).start();
        //同步等待callable的返回值
        String result = stringFutureTask.get();
        //
        System.out.println(result);
        //与callable任务中一样等待五秒才结束
        System.out.println("main线程运行结束");

    }
}
